package com.yukefms.common;

/**
 * @Description
 * @Author Ping
 * @Date 2021/6/29 10:32
 **/
public class Timer {
    long startMs ;
    long currentMs ;
    long intervalMs ;
    long deadlineMs ;

    public Timer(long intervalMs) {
        this.startMs = System.currentTimeMillis();
        this.intervalMs = intervalMs;
        this.deadlineMs = this.startMs + this.intervalMs ;
    }
    public Timer(long startMs, long intervalMs) {
        this.startMs = startMs ;
        this.intervalMs = intervalMs ;
        this.deadlineMs = this.startMs + this.intervalMs;
    }

    public boolean isExpired() {
        return System.currentTimeMillis() >= this.deadlineMs  ;
    }
    public void update() {
        reset() ;
    }
    public void reset() {
        this.startMs = System.currentTimeMillis() ;
        this.deadlineMs = this.startMs + this.intervalMs ;
    }
}

